package com.hangxiang.approval.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hangxiang.approval.common.ApproveInsertCommon;
import com.hangxiang.approval.common.ApproveUpdateCommon;
import com.hangxiang.approval.common.IntegerCommon;
import com.hangxiang.approval.dao.ApproveDao;
import com.hangxiang.approval.entity.Approve;
import com.hangxiang.approval.service.ApproveService;
import com.hangxiang.approval.vo.ApproveVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


/**
 * 审批表(Approve)表服务实现类
 *
 * @author makejava
 * @since 2020-11-23 18:06:12
 */
@Service("approveService")
public class ApproveServiceImpl extends ServiceImpl<ApproveDao, Approve> implements ApproveService {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Resource
    private ApproveDao approveDao;

    /**
     * 通过ID查询单条数据
     *
     * @param common 主键
     * @return 实例对象
     */
    @Override
    public ApproveVo queryById(IntegerCommon common) {
        ApproveVo vo = new ApproveVo();
        Approve approve = approveDao.selectById(common.getValue());
        BeanUtils.copyProperties(approve, vo);
        return vo;
    }


    /**
     * 新增数据
     *
     * @param approveInsertCommon 实例对象
     * @return 实例对象
     */
    @Override
    public Integer insertApprove(ApproveInsertCommon approveInsertCommon) {
        Approve approve = new Approve();
        BeanUtils.copyProperties(approveInsertCommon, approve);
        approveDao.insert(approve);
        return approve.getId();
    }

    /**
     * 修改数据
     *
     * @param approveUpdateCommon 实例对象
     * @return 实例对象
     */
    @Override
    public Integer updateApprove(ApproveUpdateCommon approveUpdateCommon) {
        Approve approve = new Approve();
        BeanUtils.copyProperties(approveUpdateCommon, approve);
        approveDao.updateById(approve);
        return approve.getId();
    }
}